package routers

// 路由拆分成单独的文件或者包

import (
	"gin-learn/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func helloHandler(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"messege": "hello message",
	})
}

func SetupRouter() *gin.Engine {
	r := gin.Default()
	r.GET("/hi", helloHandler)
	r.GET("/quality/:position", quality)
	r.POST("/syncQuality", syncQuality)
	r.GET("/requestCellInfo/:boxCode", requestForCellInfo)

	r.Run(":8848")
	return r
}

func requestForCellInfo(context *gin.Context) {

}

func syncQuality(context *gin.Context) {
	context.JSON(http.StatusOK, gin.H{
		"msg":  "success",
		"code": 200,
	})
}

func quality(context *gin.Context) {
	param := context.Param("position") // http://localhost:8848/quality/2
	obj := new(model.QualityStruct)
	obj.Code = param
	obj.ProductType = "210"
	obj.Measuringlength = "333"
	obj.Weight = "22"
	obj.Result = 0
	obj.Station = param
	obj.Param1 = 1
	obj.Param2 = 2

	vo := new(model.Vo)
	vo.Name = "name"
	vo.W = 1
	vo.X = 2
	vo.Y = 3
	list := []model.Vo{
		*vo,
		*vo,
		*vo,
	}
	obj.Defects = list
	context.JSON(http.StatusOK, obj)
}
